import "./index.scss";
import {Button, Card, Form, Input} from "antd";
import {useDispatch} from 'react-redux';
import {useNavigate} from "react-router-dom";
import {fetchLogin} from "@/store/modules/loginStore.jsx";

export default function Login() {


    // 调用store的数据时需要执行useDispatch函数
    const dispatch = useDispatch();
    const navigate=useNavigate();

    const onFinish = async (loginObj) => {

        const loginData={"loginName":loginObj.userName,"password":loginObj.password};
        // 触发异步action，当中fetchLogin函数是store中的异步函数，value是登录表表单的对象
        await  dispatch(fetchLogin(loginData));
        navigate("/")
    };

    return (
        <div className="login">
            <Card className="login-container">
                {/*<img className="login-logo" src={logo} alt="" />*/}
                <h1 className="h1Title">招采台账管理</h1>

                {/* 登录表单  zqdzt Djydzt123* */}
                <Form onFinish={onFinish} validateTrigger="onBlur">
                    <Form.Item
                        name="userName"
                        rules={[
                            {
                                required: true,
                                message: "请输入用户名",
                            },
                            {
                                pattern: /^[A-Za-z][^\s]{3,14}$/,
                                message: "字符数量大于3小于14，不能有空格且第一个字符不能为数字或者特殊符号",
                            },
                        ]}
                    >
                        <Input size="large" allowClear placeholder="用户名" />
                    </Form.Item>
                    <Form.Item
                        name="password"
                        rules={[
                            {
                                required: true,
                                message: "请输入密码",
                            },
                            {
                                pattern: /^(?=.*[A-Z])(?=.*[!@#$%^&*])[^0-9\s][A-Za-z0-9!@#$%^&*]{7,15}$/,
                                message:'长度6~16，第一个字符不能是数字，且必须有一个大写字母一个特殊字符！'
                            },

                        ]}
                    >
                        <Input.Password size="large" allowClear placeholder="请输入密码" value="" />
                    </Form.Item>
                    <Form.Item>
                        <Button type="primary" htmlType="submit" size="large" block>
                            登录
                        </Button>
                    </Form.Item>
                </Form>
            </Card>
        </div>
    );
};


